<template>
  <el-container>
    <el-aside width="200px">
      <el-menu
        :default-active="defaultAct"
        class="el-menu-vertical-demo"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        router
      >
        <!-- <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>导航一</span>
          </template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="1-1">选项1</el-menu-item>
            <el-menu-item index="1-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="1-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项1</el-menu-item>
          </el-submenu>
        </el-submenu> -->
        <el-menu-item index="/">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/users">
          <i class="el-icon-user-solid"></i>
          <span slot="title">用户管理</span>
        </el-menu-item>
        <el-submenu index="1">
          <template slot="title">
            <i class="el-icon-house"></i>
            <span>知识库</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/msbd/classify">
              <span slot="title">类别管理</span>
            </el-menu-item>
            <el-menu-item index="/msbd">
              <span slot="title">面试宝典</span>
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-edit"></i>
            <span>在线测试</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/test/questions">
              <span slot="title">题库管理</span>
            </el-menu-item>
            <el-menu-item index="/test">
              <span slot="title">学习模式</span>
            </el-menu-item>
             <el-menu-item index="/test">
              <span slot="title">考试模式</span>
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <!-- <el-menu-item index="/test">
          <i class="el-icon-edit"></i>
          <span slot="title">考试系统</span>
        </el-menu-item> -->
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <h2 style="display: inline-block">Bk管理系统</h2>
        <span style="color: #ccc; float: right">
          用户：{{ userInfo.name }}（{{ maps[userInfo.roles] }}）
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="mine">个人中心</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </span>
      </el-header>
      <el-main>
        <Nuxt />
      </el-main>
      <el-footer>Footer</el-footer>
    </el-container>
  </el-container>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      options: [],
      select: "",
      defaultAct: "/",
      maps: {
        admin: "管理员",
        editor: "作者",
        user: "普通用户",
      },
    };
  },
  watch: {
    $route: {
      handler(val) {
        this.defaultAct = val.path;
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    ...mapActions("users", ["logout"]),
    async handleCommand(command) {
      if (command == "logout") {
        await this.logout();
        this.$router.push("/login");
      }
    },
  },
  mounted() {
    // console.log(this.$store.getters)
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
};
</script>
<style>
html,
body,
#__nuxt,
#__layout {
  height: 100%;
}
</style>

<style scoped>
.el-container {
  height: 100%;
}
.el-header,
.el-footer {
  background-color: rgb(136, 155, 170);
  line-height: 60px;
}

.el-aside {
  background-color: #545c64;
}

.el-main {
  background-color: #e9eef3;
  padding: 0;
}

.el-menu {
  border-right: none;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>